package XYC;

import static org.junit.Assert.assertTrue;
import XYC.test.RobotTestBed;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.events.BattleCompletedEvent;

/**
 * Illustrates JUnit testing of Robocode robots.
 * This test simply verifies that YichiSpecialBot moves correctly.
 * @author Yichi Xu
 *
 */
public class TestYichiSpecialBotMovement extends RobotTestBed {
  /** Check that the robot has been to the top left corner. */
  private boolean reachTopLeft = false;
  /** Check that the robot has been to the bottom left corner. */
  private boolean reachBottomLeft = false;
  /** Check that the robot has been to the top right corner. */
  private boolean reachTopRight = false;
  /** Check that the robot has been to the bottom right corner. */
  private boolean reachBottomRight = false;
  private double height = battleFieldSpec.getHeight();
  private double width = battleFieldSpec.getWidth();
  /**
   * Specifies that SittingDuck and YichiSpecialBot are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,XYC.YichiSpecialBot";
  }
  
  /**
   * This test runs for 5 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 5;
  }
  
  /**
   * After each turn, check to see that we're in striking distance.
   * @param event Info about the current state of the battle.
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot YichiSpecialBot = event.getTurnSnapshot().getRobots()[1];
 
    double YichiSpecialBotX = YichiSpecialBot.getX();
    double YichiSpecialBotY = YichiSpecialBot.getY();
     
    if ((YichiSpecialBotX < 40) && (YichiSpecialBotY < 40)) {
      reachBottomLeft = true;
    }
    if ((YichiSpecialBotX < 40) && (YichiSpecialBotY > (height - 40))) {
      reachTopLeft = true;
    }
    if ((YichiSpecialBotX > (width - 40)) && (YichiSpecialBotY < 40)) {
      reachBottomRight = true;
    }
    if ((YichiSpecialBotX > (width - 40)) && (YichiSpecialBotY > (height - 40))) {
      reachTopRight = true;
    }   
  }
  
  /**
   * The actual test, which asserts that YichiSpecialBot 
   * visited four corners in the battlefield.
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Check to make sure YichiSpecialBot visited top left corner.
    assertTrue("Check YichiSpecialBot visit top left corner", reachTopLeft);
    // Check to make sure YichiSpecialBot visited bottom left corner.
    assertTrue("Check YichiSpecialBot visit bottom left corner", reachBottomLeft);
    // Check to make sure YichiSpecialBot visited top right corner.
    assertTrue("Check YichiSpecialBot visit top right corner", reachTopRight);
    // Check to make sure YichiSpecialBot visited bottom right corner.
    assertTrue("Check YichiSpecialBot visit bottom right corner", reachBottomRight);
  }
}